//获取二维码
$.ajax({
	    type:"post",
	    url:url+'/user/getkfcode.html?token='+token,
	    async:false,
	    data:{'token':token},
	    dataType:'json',
	    success:function(result){
	        console.log(result)
	        if(result.status === "0001"){
	        	var data=result.data;
				$(".myservice_img").attr("src",data);
	        }else{
	            isErr(result);
	        }
	    },
		error:function(){
			layer.msg("响应失败");
		}
	})
function getObjectURL(file) {
	var url = null;
	if(window.createObjectURL != undefined) { // basic
		url = window.createObjectURL(file);
	} else if(window.URL != undefined) { // mozilla(firefox)
		url = window.URL.createObjectURL(file);
	} else if(window.webkitURL != undefined) { // webkit or chrome
		url = window.webkitURL.createObjectURL(file);
	}
	return url;
}
//展示图图片预览
function showPic2(data) { //3.当用户上传图片后，触发input标签的onchange事件，执行showPic()方法
	var objUrl = getObjectURL(data.files[0]);

	if(data.files && data.files[0]) { //4.判断input标签的file是否存在

		var reader = new FileReader(); //5.实例化一个FileReader()接口

		reader.readAsDataURL(data.files[0]); //6.通过readAsDataURL()方法读取文件，将图片内嵌在网页之中

		reader.onload = function(evt) { //7.调用FileReader()的onload事件，当文件读取成功时，执行8

			//8.将reader的result属性值赋值给data.parentNode.childNodes[1].childNodes[1].src，实现图片预览

			//              $("#psfsremove").remove()
			//删除图片
			$(".colsed").on("click", function() {
				var that = this;
				$(that).parents(".psfspic").remove()
			})
		}
	}
}

$("#dtxz").change(function() {
	dialog("#d1");
	var formData=new FormData($( "#form1")[0]);
	var fileObj = $("#dtxz")[0].files;
	formData.append("token",token);
	$.ajax({
		type: 'post',
		dataType: 'json',
		url: url+'/user/comuphoto.html?token='+token ,
		async:false,
		cache: false,
		data:formData,
		processData: false,
		contentType: false,
		success:function (result) {
			
			if(result.status == '0001'){
				dialog("#d1",2000);
				var html = 
				'<div class="psfspic">\n' +
					'<img src="' + result.src + '" alt="" class="sct"/>\n' +
					'<img src="../images/close2.png" alt="" class="colsed"/>\n' +
				'</div>'
				$("#psfspic1d").prepend(html)
				var length = $("#psfspic1d .psfspic").length;
				for(var i = 0;i <= length;i++) {
					num = i-1
				}
				$("#psfspic1d .psfspic").eq(num).children(".zhutuhidden").val(result.src);
				// layer.msg(result.message);
//	        	  $(".sct").attr("src",result.src);
			}else{
				dialogClose();
				isErr(result);
			}
		}
	})
})

//提交
var prevent_repetition=true;
	$("#lianxikefu").on("click",function(){
		if(prevent_repetition){
			prevent_repetition=false;
			var describe=$(".myservice_text").val();
			
			var arr=[];
			if(!describe){
				layer.msg("请输入问题");
				prevent_repetition=true;
				return false;
			}			
			for(var i=0;i<$(".psfspic").length-1;i++){
				arr.push($(".psfspic").eq(i).find("img").attr("src"));	
			}
			var d={};
			d.token=token;
			d.describe=describe;
			d.src=arr.join(",");
			$.ajax({
			    type:"post",
			    url:url+'/user/comsubmit.html?token='+token,
			    async:false,
			    data:d,
			    dataType:'json',
			    success:function(result){
			        if(result.status == "0001"){
						layer.msg(result.message);
						location.href="myservice_list.html";
			        }else{
			            isErr(result);
			        }
			    },
				error:function(){
					layer.msg("响应失败");
				},
				complete: function() {
					prevent_repetition = true;
				}
			})
		}
	})